using System;
using Firestarter.Test.Base;
using FireStarterModeller.BO;
using Habanero.Base;
using Habanero.BO;
using NUnit.Framework;

namespace FireStarterModeller.Test.BO
{
    [TestFixture]
    public class TestDMInheritanceRelationshipDiscriminatorMustBeCompulsoryAndWriteOnce
    {
       [SetUp]
        public void SetupTest()
        {
            //Runs every time that any testmethod is executed
            TestUtilsDomain.SetupTest();
            BORegistry.DataAccessor = new DataAccessorInMemory();
        }

        [TestFixtureSetUp]
        public void TestFixtureSetup()
        {
            //Code that is executed before any test is run in this class. If multiple tests
            // are executed then it will still only be called once.
            TestUtilsDomain.SetupFixture();
        }

        [TearDown]
        public void TearDownTest()
        {
            //runs every time any testmethod is complete
        }

        #region TestInheritanceRelationshipDiscriminatorMustBeStringProp


        [Test]
        public void Test_Contruct()
        {
            //---------------Set up test pack-------------------
            DMInheritanceRelationship dmInheritanceRelationship = new DMInheritanceRelationship();
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            IBusinessObjectRule rule =
                new DMInheritanceRelationshipDiscriminatorMustBeCompulsoryAndWriteOnce(dmInheritanceRelationship);
            //---------------Test Result -----------------------
            Assert.IsNotNull(rule);
            Assert.AreEqual("DMInheritanceRelationshipDiscriminatorMustBeCompulsoryAndWriteOnce", rule.Name);
            Assert.AreEqual(ErrorLevel.Warning, rule.ErrorLevel);
        }

       
        [Test]
        public void Test_WhenInheritanceRelationshipNull_ShouldRaiseError()
        {
            //---------------Set up test pack-------------------
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            try
            {
                new DMInheritanceRelationshipDiscriminatorMustBeCompulsoryAndWriteOnce(null);
                Assert.Fail("expected ArgumentNullException");
            }
                //---------------Test Result -----------------------
            catch (ArgumentNullException ex)
            {
                StringAssert.Contains("Value cannot be null", ex.Message);
                StringAssert.Contains("inheritanceRelationship", ex.ParamName);
            }
        }

        [Test]
        public void Test_IsValid_WhenDiscriminatorHasNoValue_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMInheritanceRelationship dmInheritanceRelationship = new DMInheritanceRelationship();
            IBusinessObjectRule rule =
                new DMInheritanceRelationshipDiscriminatorMustBeCompulsoryAndWriteOnce(dmInheritanceRelationship);
            //---------------Assert Precondition----------------
            Assert.IsNull(dmInheritanceRelationship.Discriminator);
            //---------------Execute Test ----------------------
            bool isValid = rule.IsValid();
            //---------------Test Result -----------------------
            Assert.IsFalse(isValid);
        }

        [Test]
        public void Test_IsValid_WhenDiscriminatorHasValue_ShouldReturnTrue()
        {
            //---------------Set up test pack-------------------
            DMInheritanceRelationship dmInheritanceRelationship = new DMInheritanceRelationship();
            DMProperty property = TestUtilsDMProperty.CreateUnsavedValidDMProperty();
            property.PropertyName = "Value";
            dmInheritanceRelationship.Discriminator = property.PropertyName;
           
            IBusinessObjectRule rule =
                new DMInheritanceRelationshipDiscriminatorMustBeCompulsoryAndWriteOnce(dmInheritanceRelationship);
            //---------------Assert Precondition----------------
            Assert.IsNotNull(dmInheritanceRelationship.Discriminator);
            Assert.AreEqual(property.PropertyName,dmInheritanceRelationship.Discriminator);
            //---------------Execute Test ----------------------
            bool isValid = rule.IsValid();
            //---------------Test Result -----------------------
            Assert.IsTrue(isValid);
        }

        [Ignore("Waji working on this")] //TODO Brett 22 Feb 2010: Ignored Test - Waji working on this
        [Test]
        public void Test_IsValid_WhenDiscriminatorNotWriteOnce_ShouldReturnFalse()
        {
            //---------------Set up test pack-------------------
            DMInheritanceRelationship dmInheritanceRelationship = new DMInheritanceRelationship();
            DMProperty property = TestUtilsDMProperty.CreateUnsavedValidDMProperty();
//            property.ReadWriteRule = PropReadWriteRule.ReadWrite;
            
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------

            //---------------Test Result -----------------------
            Assert.Fail("Not Yet Implemented");
        }

        /* 
       [Test]
       public void Test_IsValid_FailsIfNotStringPropertyType()
       {
           //---------------Set up test pack-------------------
           DMProperty dmProperty = TestUtilsShared.CreateSavedDMProperty();
           TestUtilsDMProperty.SetDMPropIntType(dmProperty);
           dmProperty.Save();
           DMInheritanceRelationship dmInheritanceRelationship = new DMInheritanceRelationship();
           DMClass subClass = TestUtilsShared.CreateSavedDMClass(dmProperty.Class.Assembly);
           dmInheritanceRelationship.SubClass = subClass;
           dmInheritanceRelationship.SuperClass = dmProperty.Class;
           dmInheritanceRelationship.Discriminator = dmProperty.PropertyName;
           subClass.Save();
           dmInheritanceRelationship.Save();
           IBusinessObjectRule rule = new DMInheritanceRelationshipDiscriminatorMustBeStringProp(dmInheritanceRelationship);
           //---------------Assert Precondition----------------
           Assert.AreEqual(ORMapping.SingleTableInheritance, dmInheritanceRelationship.InheritanceType);
           Assert.IsNotNull(dmInheritanceRelationship.SubClass);
           Assert.IsNotNull(dmInheritanceRelationship.Discriminator);
           Assert.AreNotEqual(DMPropertyType.PROP_TYPE_STRING, dmProperty.PropertyTypeString);
           //---------------Execute Test ----------------------
           bool isValid = rule.IsValid();
           //---------------Test Result -----------------------
           Assert.IsFalse(isValid);
           TestUtilsShared.AssertStringNotEmpty(rule.Message, "rule.Message");
       }
       [Test]
       public void Test_IsValid_WhenCustomPropertyType_ShouldPass()
       {
           //---------------Set up test pack-------------------
           DMProperty dmProperty = TestUtilsShared.CreateSavedDMProperty();
           TestUtilsDMProperty.SetDMPropCustomType(dmProperty);
           dmProperty.Save();
           DMInheritanceRelationship dmInheritanceRelationship = new DMInheritanceRelationship();
           DMClass subClass = TestUtilsShared.CreateSavedDMClass(dmProperty.Class.Assembly);
           dmInheritanceRelationship.SubClass = subClass;
           dmInheritanceRelationship.SuperClass = dmProperty.Class;
           dmInheritanceRelationship.Discriminator = dmProperty.PropertyName;
           subClass.Save();
           dmInheritanceRelationship.Save();
           IBusinessObjectRule rule = new DMInheritanceRelationshipDiscriminatorMustBeStringProp(dmInheritanceRelationship);
           //---------------Assert Precondition----------------
           Assert.AreEqual(ORMapping.SingleTableInheritance, dmInheritanceRelationship.InheritanceType);
           Assert.IsNotNull(dmInheritanceRelationship.SubClass);
           Assert.IsNotNull(dmInheritanceRelationship.Discriminator);
           Assert.AreNotEqual("System", dmProperty.PropertyType.AssemblyName);
           //---------------Execute Test ----------------------
           bool isValid = rule.IsValid();
           //---------------Test Result -----------------------
           Assert.IsTrue(isValid);
       }

       [Test]
       public void Test_IsValid_PassesIfInheritanceTypeIsConcrete()
       {
           //---------------Set up test pack-------------------
           DMInheritanceRelationship dmInheritanceRelationship = new DMInheritanceRelationship();
           dmInheritanceRelationship.InheritanceType = ORMapping.ConcreteTableInheritance;
           IBusinessObjectRule rule = new DMInheritanceRelationshipDiscriminatorMustBeStringProp(dmInheritanceRelationship);
           //---------------Assert Precondition----------------
           Assert.AreEqual(ORMapping.ConcreteTableInheritance, dmInheritanceRelationship.InheritanceType);
           //---------------Execute Test ----------------------
           bool isValid = rule.IsValid();
           //---------------Test Result -----------------------
           Assert.IsTrue(isValid);
       }

       [Test]
       public void Test_IsValid_WhenClassTableInheritanceAndDiscrimatorEmpty_ShouldReturnTrue()
       {
           //---------------Set up test pack-------------------
           DMInheritanceRelationship dmInheritanceRelationship = new DMInheritanceRelationship();
           dmInheritanceRelationship.InheritanceType = ORMapping.ClassTableInheritance;
           IBusinessObjectRule rule = new DMInheritanceRelationshipDiscriminatorMustBeStringProp(dmInheritanceRelationship);
           //---------------Assert Precondition----------------
           TestUtilsShared.AssertStringEmpty(dmInheritanceRelationship.Discriminator, "dmInheritanceRelationship.Discriminator");
           //---------------Execute Test ----------------------
           bool isValid = rule.IsValid();
           //---------------Test Result -----------------------
           Assert.IsTrue(isValid);
       }

       [Test]
       public void Test_IsValid_PassesIfStringPropertyType()
       {
           //---------------Set up test pack-------------------
           DMProperty dmProperty = TestUtilsShared.CreateSavedDMProperty();
           TestUtilsDMProperty.SetDMPropStringType(dmProperty);
           dmProperty.Save();
           DMInheritanceRelationship dmInheritanceRelationship = new DMInheritanceRelationship();
           DMClass subClass = TestUtilsShared.CreateSavedDMClass(dmProperty.Class.Assembly);
           dmInheritanceRelationship.SubClass = subClass;
           dmInheritanceRelationship.SuperClass = dmProperty.Class;
           dmInheritanceRelationship.Discriminator = dmProperty.PropertyName;
           subClass.Save();
           dmInheritanceRelationship.Save();
           IBusinessObjectRule rule = new DMInheritanceRelationshipDiscriminatorMustBeStringProp(dmInheritanceRelationship);
           //---------------Assert Precondition----------------
           Assert.AreEqual(ORMapping.SingleTableInheritance, dmInheritanceRelationship.InheritanceType);
           Assert.IsNotNull(dmInheritanceRelationship.SubClass);
           Assert.IsNotNull(dmInheritanceRelationship.Discriminator);
           Assert.AreEqual(DMPropertyType.PROP_TYPE_STRING, dmProperty.PropertyTypeString);
           //---------------Execute Test ----------------------
           bool isValid = rule.IsValid();
           //---------------Test Result -----------------------
           Assert.IsTrue(isValid);
       }

*/
        #endregion
    }
}